package main

import (
	"github.com/gin-gonic/gin"
)

func customMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		ref := c.GetHeader("Referer")
		if ref == "" {
			c.AbortWithStatusJSON(200, gin.H{
				"msg": "非法请求",
			})
			return
		}
		c.Next()
	}
}
func main() {
	router := gin.Default()
	// 全局只用中间件，所有的调用都会被执行
	router.Use(customMiddleware())
	// 单个handler添加middleware
	router.POST("/user", createGoods)

	router.Run(":8083")
}

func createGoods(c *gin.Context) {
	c.JSON(200, gin.H{
		"msg": "success",
	})
}
